﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

using D3Sparrow.Core.Common;

namespace D3Sparrow.Core.Structures
{
    [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi, Size = 0x2D0)] //Offsets.ACDSize)
    unsafe public struct ActorCommonData
    {
        public uint id_acd;                // 0x000
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
        public char[] _name;               // 0x004
        public uint unk_0;                 // 0x084 
        public uint id_unk1;               // 0x088 
        public uint id_actor;              // 0x08C 
        public uint id_sno;               // 0x090 
        public fixed byte unknown_94[28];  // 0x094 
        public uint gb_type;               // 0x0B0  
        public uint id_gb;                 // 0x0B4
        public MobRareType rtype;          // 0x0B8
        public fixed byte unknown_B8[20];  // 0x0BC 
        public Vec3 PosWorld;              // 0x0D0 
        public fixed byte unknown_DC[36];  // 0x0DC 
        public float RadiusDefault;        // 0x100 
        public fixed byte unknown_104[4];  // 0x104 
        public uint id_world;              // 0x108 
        public fixed byte unknown_10C[4];  // 0x10C 
        public uint id_owner;              // 0x110 
        public ItemLocation itemLoc;       // 0x114
        public uint itemX;                   // 0x118
        public uint itemY;                   // 0x11C
        public uint id_attrib;               // 0x120         public uint id_unk3;               // 0x124 
        public fixed byte unknown_128[244];// 0x128 
        public byte NBAD848;               // 0x21C 
        public byte RadiusType;            // 0x21D 
        public byte NBB56E9;               // 0x21E 
        public byte NBBA038;               // 0x21F 
        public fixed byte unknown_220[24]; // 0x220 
        public float RadiusScaled;         // 0x238 
        public fixed byte unknown_23C[148];// 0x23C 

        public uint mem_location; // used for checking for changes later on

        public string name
        {
            get
            {
                return new string(_name).TrimEnd(new char[] { (char)0 });
            }
        }

        /// <summary>
        /// Checks to see if the object at the memory location is still the same.
        /// </summary>
        /// <returns>Returns true if the GUID/id_actor has not changed.</returns>
        public bool IsValid()
        {
            return (Globals.MR.ReadMemoryAsUint(mem_location) == id_acd);
        }
    }
}
